//
//  SettingViewController.swift
//  maosheng
//
//  Created by lxl on 2019/8/16.
//

import UIKit
import Kingfisher
class SettingViewController: RootViewController {

    @IBOutlet weak var logOutBtn: UIButton!
    @IBOutlet weak var sizeLab: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
    
        
        KingfisherManager.shared.cache.calculateDiskCacheSize { (size) in
            let sizeM = String(format: "%.1f", CGFloat(size)/1024/1024)
            self.sizeLab.text = "\(sizeM)M"
            print("当前的缓存的大小,这地方获取的是b,记得转化为M======\(size)")
        }
        
        logOutBtn.setTitle(UserInfo.getUserIsLogged() ? "退出登录" : "登录", for: .normal)
    }

    @IBAction func aboutUs(_ sender: Any) {
        let web = PublicWebViewController()
        web.str_title = "关于我们"
        web.webURLStr = about
        self.navigationController?.pushViewController(web, animated: true)
    }
    @IBAction func clearCache(_ sender: Any) {
        PublicTools.showAlert(currentVC: self, meg: "确定清理缓存", cancelBtn: "取消", otherBtn: "确定") { (action) in
            let cache = KingfisherManager.shared.cache
            cache.clearDiskCache()//清除硬盘缓存
            cache.clearMemoryCache()//清理网络缓存
            cache.cleanExpiredDiskCache()//清理过期的，或者超过硬盘限制大小的
            self.sizeLab.text = "0M"
        }
       
    }
    @IBAction func loginOrLogOut(_ sender: Any) {
        PublicTools.showAlert(currentVC: self, meg: "退出登录", cancelBtn: "取消", otherBtn: "确定") { (action) in
            UserInfo.userLogOut()
            if let app = UIApplication.shared.delegate as? AppDelegate{
                app.createRootViewController()
            }
        }
        
    }
    
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
